<?php

	error_reporting(E_ALL ^ E_NOTICE);
	ini_set('display_errors', '1');

	include_once('config.php');

	//  $id = $_REQUEST['conversionID'];
	// if file_exist get the json value else set an error message and show that in the body of the webpage
	//	file_get_contents({path} {$id}
	//	load the variables and display the message accordingly in the body. If file is ready make sure to include link so they cna download
	//	If the status is still pending in the queue refresh every 30 seconds until it is found.
	//	<meta http-equiv="refresh" content="30;URL=" />
	//	exit();

	$conversionID = @trim($_REQUEST['conversionID']);
	$pickUpPath .= $conversionID . '.json';

	if(@file_exists($pickUpPath)) {
		$details = @file_get_contents($pickUpPath);
		$details = json_decode($details,true);
		$status = $details['status'];
		$zipPath = $details['path'];
	}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
if(!$status) {
	echo '<meta http-equiv="refresh" content="30;URL=" />';
}
?>
<title>Gbif - Template Conversion Tool</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
body {
	margin-left: 10px;
	margin-top: 10px;
}
-->
</style></head>

<body link="#3EB549" vlink="#3DB549" alink="#3EB549">
<h1><img src="gbif_icon.jpg" width="64" height="64" alt="GBif" /> Template to DwC Archive Converson Service
</h1>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
	<tr>
		<td width="56%"><p>Conversion ID: <?=$conversionID?></p>
		<p>Status: <?php echo ($status == false) ? 'Processing' : 'Ready'; ?></p>
		<p>Darwin Core Archive: <?php echo "<a href='$zipPath'>$zipPath</a>"; ?></p>
		<p>If your status is still pending that means your Excel file is still in the queue to get processed. This website will refresh every 30 seconds until the Darwin Core Archive is available. You may also copy this link and check back later. The average time to process a template is around 1-5 minutes. Any questions please contact: <a href="mailto:support@gbif.org">support@gbif.org</a></p></td>
	</tr>
</table>
</body>
</html>
